// components/music-list/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    playList: {
      type: Object
    }
  },
  observers: {
    ['playList.playCount'](val) {
      this.setData({
        count: this.formatCount(val, 2)
      })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    count: 0
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 格式化数字
    formatCount(num, point) {
      let numStr = num.toString().split('.')[0]
      if (numStr.length < 6) {
        return numStr
      } else if (numStr.length >= 6 && numStr.length <= 8) {
        let decimal = numStr.substring(numStr.length - 4, numStr.length - 4 + point)
        return `${parseInt(num / 10000)}.${decimal}万`
      } else if (numStr.length > 8) {
        let decimal = numStr.substring(numStr.length - 8, numStr.length - 8 + point)
        return `${parseInt(num / 100000000)}.${decimal}亿`
      }
    }
  }
})